/**
 * 
 */
package com.leoj.utils.tcp_network.tcp_server;

import java.io.IOException;
import java.net.Socket;

import com.leoj.utils.tcp_network.ApplicationProtocol;
import com.leoj.utils.tcp_network.ApplicationProtocolFactory;
import com.leoj.utils.tcp_network.TcpConnection;
import com.leoj.utils.tcp_network.TcpServerSocketThread;

/**
 * @author leoj
 *
 */
public class SingleThreadTcpServer extends TcpServerSocketThread {

	/**
	 * @param port
	 * @throws IOException
	 */
	public SingleThreadTcpServer(int port, ApplicationProtocolFactory factory) throws IOException {
		super(port, factory);
	}
	public SingleThreadTcpServer(int port, int timeout, ApplicationProtocolFactory factory) throws IOException {
		super(port, timeout, factory);
	}
	/* (non-Javadoc)
	 * @see com.leoj.utils.network.TcpServerSocketThread#handleNewConnection(java.net.Socket)
	 */
	@Override
	protected void handleNewConnection(Socket s) {
		TcpConnection connection = null;
		try {
			connection = new TcpConnection(s);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		ApplicationProtocol protocol = _protocolFactory.createProtocol();
		protocol.handleClient(connection);
	}

}
